package com.itsci.assignment2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class EditGuide extends Activity{
	private EditText name;
	private EditText tel;
	private EditText email;
	private Button save;
	private GuideManager guideMgr;
	private String intentName;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.edit_guide);
		name = (EditText)findViewById(R.id.editText_editGuide_name);
		tel = (EditText)findViewById(R.id.editText_editGuide_tel);
		email = (EditText)findViewById(R.id.editText_editGuide_email);
		Intent intent = getIntent();
		intentName = intent.getStringExtra("name");
		name.setText(intent.getStringExtra("name"));
		tel.setText(intent.getStringExtra("tel"));
		email.setText(intent.getStringExtra("email"));
		save = (Button)findViewById(R.id.button_editGuide_save);
		guideMgr = new GuideManager(EditGuide.this, null, null, 1);
		
		save.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				GuideBean guideBean = new GuideBean(guideMgr.getId(intentName),name.getText().toString(),tel.getText().toString(),email.getText().toString());
//				guideBean.setId();
//				guideBean.setGuidName();
//				guideBean.setTel();
//				guideBean.setEmail();
				guideMgr.updateGuide(guideBean);
				Intent gotoEdit = new Intent(EditGuide.this,ShowGuide.class);
				gotoEdit.putExtra("name",name.getText().toString());
				gotoEdit.putExtra("tel",tel.getText().toString());
				gotoEdit.putExtra("email",email.getText().toString());
				setResult(111,gotoEdit);
				finish();
				
			}
		});
		
		
	}

}
